package com.cdtu.outtake.common;

import com.cdtu.outtake.MyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author : shl
 * @Date 2024/4/10 7:45
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandlerController {

    @ExceptionHandler(MyException.class)
    public Result<Object> myExceptionHandle(MyException exception) {
        log.error(exception.getMessage());
        exception.printStackTrace();
        return Result.fail(exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<Object> unknownExceptionHandle(Exception exception) {
        log.error("产生了异常,具体信息：" + exception.getMessage());
        exception.printStackTrace();
        return Result.fail("服务器未知异常");
    }
}
